package org.activequant.data.preparation;

import org.activequant.core.domainmodel.data.MarketDataEntity;
import org.activequant.core.domainmodel.data.TimeSeries;
import org.activequant.core.util.TimeSeriesUtils;

/**
 * An abstract class. Extends the FilterBase abstract class (which implements the IFilter interface).
 * <br>
 *       <b>History:</b><br>
 *       - [30.01.2008] Created (Erik Nijkamp)<br>
 * 
 * @author Erik Nijkamp
 */
public abstract class TransformFilterBase extends FilterBase {
	/**
	 * Returns a clone CandleSeries[] of the given series(T...) in which every Candle has its openPrice(double), highPrice(double), lowPrice(double) and closePrice(double) transformed
	 * using the <code>transform()</code> method
	 */
	@Override
	protected <U extends MarketDataEntity<U>, T extends TimeSeries<U>> T[] processSeries(Class<U> clazz, T... series) throws Exception {
		T[] newSeries = cloneSeries(clazz, series);
		for (int i = 0; i < series.length; i++) {
			newSeries[i] = processSeries(clazz, series[i]);
		}
		return newSeries;
	}
	/**
	 * Returns a clone CandleSeries of the given series(T) in which every Candle has its openPrice(double), highPrice(double), lowPrice(double) and closePrice(double) transformed
	 * and set with the transformed value.
	 * @param <U>
	 * @param <T>
	 * @param clazz
	 * @param series
	 * @return
	 * @throws Exception
	 */
	protected <U extends MarketDataEntity<U>, T extends TimeSeries<U>> T processSeries(Class<U> clazz, T series) throws Exception {
		// clone original
		T newSeries = cloneSeries(clazz, series);
		// calculate
		double[][] values = transform(TimeSeriesUtils.getSeriesValues(series), series.size());
		// set
		TimeSeriesUtils.setSeriesValues(newSeries, values);
		// done
		return newSeries;
	}
	/**
	 * abstract method. Should transform the given openPrice(double)'s, highPrice(double)'s, lowPrice(double)'s and closePrice(double)'s and return them
	 * @param values
	 * @param size
	 * @return
	 */
	protected abstract double[][] transform(double[][] values, int size);
}
